package logic

import (
	"context"
	"encoding/json"

	"diff.wang/asynqsrv/common"
	"diff.wang/asynqsrv/server/internal/svc"
	"github.com/hibiken/asynq"
	"github.com/zeromicro/go-zero/core/logx"
)

type PhoneDeliveryTask struct {
	svcCtx *svc.ServiceContext
}

func NewPhoneDeliveryTask(svcCtx *svc.ServiceContext) *PhoneDeliveryTask {
	return &PhoneDeliveryTask{
		svcCtx: svcCtx,
	}
}

func (task *PhoneDeliveryTask) ProcessTask(ctx context.Context, t *asynq.Task) error {

	var p common.PhoneDeliveryPayload
	if err := json.Unmarshal(t.Payload(), &p); err != nil {
		return err
	}
	logx.Info("%s gets processed successfully by a worker,taskId: %v\n", common.MsgEmailDelivery, t.ResultWriter().TaskID())
	return nil
}
